package karileet.meeting.profile;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Vibrator;
import android.util.Log;
 
/**
 * Class overrides broadcastreceiver onreceive method and plays notification 
 * sound when app is enabled. Also 1000ms vibrate is initiated, when app is set
 * to vibrate (normal vibrate profile does not vibrate when SMS is received)
 * 
 * @author markus karileet
 */
public class SMSReceiver extends BroadcastReceiver {
	private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
	
	@Override
	public void onReceive(Context ctx, Intent intent) {
		ProfileState state = new ProfileState(ctx);
		if (intent.getAction().equals(ACTION) && state.isProfileEnabled()) {
			Log.d(MainActivity.APP, "Recieved SMS, playing sound!");
			SoundManager sm = new SoundManager(ctx);
			//vibrate since SMS doesn't vibrate when conf is set to vibrate
			if (state.isVibrateEnabled()) {
				Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
				v.vibrate(1000);
			}
	    	sm.play(); //Dependent of music, video & other media volume setting
		}
	}
}